<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Attendance Report</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link href="./EldercareMasterPage/_finalstyle.css" rel="stylesheet" />
	<link href="./css/bootstrap.min.css" rel="stylesheet" media="screen">
    <link href="./css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
</head>
<?php
	define('CONFIG_FILE',true);
	include './config.php';
	
	session_start();
	if (empty($_SESSION["username"])) {
		Header("Location: ./Index.php");
		exit();
	}
	if (!empty($_SESSION["userType"])) {
		$userType = $_SESSION["userType"];
	}
	define('DB_FILE',true);
	// set timeout period in seconds
	$inactive = 7200;
	// check to see if $_SESSION['timeout'] is set
	if (isset($_SESSION["timeout"])) {
		$session_life = time() - $_SESSION["timeout"];
		if ($session_life > $inactive) {
			session_destroy();
			Header("Location: Timeout.php");
		}
	}
	$_SESSION["timeout"] = time();
?>
<body>
    <div class="banner">
	</div>
	<div id="main">
		<div class="left-wrapper">
			<div class="logo">
				<img src="images/eldercare.gif" alt="logo" width="240px" />
			</div>
			<div class="menu-wrapper">
				<div id="cssmenu">        
						<?php
						if ($userType == "Therapy Assistant") {
							include_once('./Sidebar/_SidebarTA.php');
						} else if ($userType == "Centre Manager") {
							include_once('./Sidebar/_SidebarCM.php');
						} else {
							include_once('./Sidebar/_SidebarSA.php');
						}
						?>                     
				</div> 
				<div class="clear"></div></div>
		</div>
		<div id="content">		
			<div class="content2">
				<b style="float:right; margin: 0px 0 0 0">  
					<?php
						if (!empty($_SESSION["centreName"])) {
							$Username = $_SESSION["username"];
							$centreName = $_SESSION["centreName"];
							echo "Welcome, " . $Username  ."! ". $centreName . " Branch.";
						} else {
							$Username = $_SESSION["username"];
							echo "Welcome, " . $Username;
						}
					?>
					<input type="submit" class="btn btn-danger" value="Logout" onclick="parent.location = 'logout.php'">
				</b>
				</p>
                <br>
				<div style="float:center">
				<br>		
				<h3>Attendance Reports</h3>
				<br>
				<form name="reportdates" method="POST" class="form-horizontal">
						<div class="control-group">
							<b>From:</b>
							<div class="controls input-append date form_date1" data-link-field="dtp_input1">
								<input  size="16" type="text" value="" readonly>
								<span class="add-on"><i class="icon-remove"></i></span>
								<span class="add-on"><i class="icon-th"></i></span>
							</div>
							<input name="startDate"  type="hidden" id="dtp_input1" value="" />
							<b>&nbsp; &nbsp; To:</b>
							<div name="endDate" class="controls input-append date form_date2" data-link-field="dtp_input2">
								<input size="16" type="text" value="" readonly>
								<span class="add-on"><i class="icon-remove"></i></span>
								<span class="add-on"><i class="icon-th"></i></span>
							</div>
							<input name="endDate"  type="hidden" id="dtp_input2" value="" />
							<?php
								if ($userType == "System Admin") {
									echo"<b> &nbsp; &nbsp; Center: </b> <select name='ddlCentre'> <option value='0'selected>All</option>";
									//****************************************//
									//****************************************//
									require_once './Tool/DB/SqlDBManager.class.php';
									$sqlDBManager = new SqlDBManager();
									$sql="Select CentreId, CentreName FROM centre";
									$res=$sqlDBManager->queryRows($sql);
									if(!empty($res)){
										for($i=0;$i<count($res);$i++){
											echo "<option value='".$res[$i]['CentreId']."'>".$res[$i]['CentreName']."</option>";
										}
									}									
									echo"</select>";
								}
							?>
							<b>&nbsp; &nbsp; Sort By:</b>
							<select id="sortBy" name="sortBy">
								<option value="NRIC" selected>NRIC</option>
								<option value="CustomerName">Customer Name</option>
								<?php
									if ($userType == "System Admin") {
										echo "<option value='CentreId'>Centre Name</option>";
									}
								?>
								<option value="Citizenship">Citizenship</option>
								<option value="Daycare">Daycare</option>
							</select>
							&nbsp; &nbsp;<input type="submit" button class="btn"id="submit" value ='Submit'name="submit"/>
						</div>					
					</form>
				</p>
				<p></p>
				<p>
				<?php
					if (isset($_POST['submit'])) {
						if (!empty($_POST['startDate'])&&!empty($_POST['endDate'])) {
							include_once('Reports/createdatetable.php');		
						}else {
							echo "<font color=red>Please pick two dates.</font>";
						}
					}
				?>
			</div>
			<div class="clear"></div>
		</div>
		</div>
	</div>
<div id="footer">&copy; 2013 MP22 IIT-IT Temasek Polytechnic</div>
</body> 
<script type="text/javascript" src="./js/jquery-1.8.3.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="./js/bootstrap.min.js"></script>
<script type="text/javascript" src="./js/bootstrap-datetimepicker.js" charset="UTF-8"></script>
<script type="text/javascript">
	$('.form_date1').datetimepicker({
		format:"dd/mm/yyyy",
        weekStart: 0,
        todayBtn:  1,
		autoclose: 1,
		todayHighlight: 1,
		startView: 2,
		minView: 2,
		forceParse: 0,
		pickerPosition:'bottom-left',
		daysOfWeekDisabled: "0,6",
    });
	$('.form_date2').datetimepicker({
		format:"dd/mm/yyyy",
        weekStart: 0,
        todayBtn:  1,
		autoclose: 1,
		todayHighlight: 1,
		startView: 2,
		minView: 2,
		forceParse: 0,
		pickerPosition:'bottom-left',
		daysOfWeekDisabled: "0,6",
    });

    $(function(){
        $('.form_date1 input,.form_date2 input').change(function(){
            var strEndDate=$('.form_date2 input').val();
            var strStartDate=$('.form_date1 input').val();
            $('.form_date1').datetimepicker('setEndDate', strEndDate);
            $('.form_date2').datetimepicker('setStartDate', strStartDate);
        });
    });
</script>
</html>

